/*
 * Copyright 2008 Lucifer Lu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Windows.Browser;

namespace SilverChart.Core.Log {
    /// <summary>
    /// Description of DefaultMessageFormater.
    /// </summary>
    class DefaultLogMessageFormater : LogMessageFormater {
        public DefaultLogMessageFormater() {
        }

        public String formatFatalMessage(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {
            return HttpUtility.HtmlEncode(log);
        }

        public String formatErrorMessage(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {
            return HttpUtility.HtmlEncode(log);
        }

        public String formatWarnMessage(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {
            String message = String.Format(Logger.LoggerConfig.WarnFormat, "Warn", HttpUtility.HtmlEncode(log), formatDateTime(time), codeFile, lineNo.ToString());
            if (e != null) {
                message += "\n";
                message += e.Message;
            }

            return message;
        }

        public String formatInfoMessage(String log, DateTime time, String codeFile, Int32 lineNo) {
            return String.Format(Logger.LoggerConfig.InfoFormat, "INFO", HttpUtility.HtmlEncode(log), formatDateTime(time), codeFile, lineNo.ToString());
        }

        public String formatDebugMessage(String log, DateTime time, String codeFile, Int32 lineNo) {
            return String.Format(Logger.LoggerConfig.DebugFormat, "DEBUG", HttpUtility.HtmlEncode(log), formatDateTime(time), codeFile, lineNo.ToString());
        }

        private String formatDateTime(DateTime time) {
            return time.ToString("hh:mm:ss.FFF");
        }
    }
}
